﻿using System;
using System.Text;

namespace SwissTransTracker
{
    /// <summary>
    ///     See transport.opendata.ch
    /// </summary>
    public class Location
    {
        /// <summary>
        ///     The id of the location
        /// </summary>
        public int? Id { get; set; }

        /// <summary>
        ///     Type of the location, can contain: •station: Location is a train station, bus station
        ///     poi: Location is a point of interest (Clock tower, China garden)
        ///     address: Location is an address
        ///     refine: Location is not defined, the user has to relocate
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        ///     The location name
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        ///     The accuracy of the result
        /// </summary>
        public int? Score { get; set; }

        /// <summary>
        ///     The location coordinates
        /// </summary>
        public Coordinates Coordinates { get; set; }

        /// <summary>
        ///     If search has been with coordinates, distance to original point in meters
        /// </summary>
        public int? Distance { get; set; }

        public override string ToString()
        {
            var sb = new StringBuilder();
            if (Name != null) sb.AppendFormat("Name: {0}{1}", this.Name, Environment.NewLine);
            if (Id != null) sb.AppendFormat("Id: {0}{1}", this.Id, Environment.NewLine);
            if (Score != null) sb.AppendFormat("Score: {0}{1}", this.Score, Environment.NewLine);
            if (Type != null) sb.AppendFormat("Type: {0}{1}", this.Type, Environment.NewLine);
            if (Coordinates != null) sb.AppendFormat("Coordinates: {1}{0}", this.Coordinates.ToString().Replace(Environment.NewLine, Environment.NewLine+'\t'), Environment.NewLine);
            if (Distance != null) sb.AppendFormat("Distance: {0}", this.Distance);
            return sb.ToString();
        }
    }
}